home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / progs / lib / hbc / Miranda.hs < prev    next >
Encoding:
Text File  |  1994-09-27  |  2.0 KB  |  91 lines  |  [TEXT/YHS2]

  1. module Miranda(cjustify, lay, layn, limit, ljustify, merge, rep, rjustify, spaces,
  2.            {-force,seq,-}sort) where
  3. --import UnsafeDirty
  4. import QSort
  5.  
  6. cjustify :: Int -> String -> String
  7. cjustify n s = spaces l ++ s ++ spaces r
  8.                where
  9.                m = n - length s
  10.                l = m `div` 2
  11.                r = m - l
  12.  
  13. {-
  14. index :: [a] -> [Int]
  15. index xs = f xs 0
  16.         where f []     n = []
  17.               f (_:xs) n = n : f xs (n+1)
  18. -}
  19.  
  20. lay :: [String] -> String
  21. lay = concat . map (++"\n")
  22.  
  23. layn :: [String] -> String
  24. layn =  concat . zipWith f [1..]
  25.            where
  26.        f :: Int -> String -> String
  27.            f n x = rjustify 4 (show n) ++ ") " ++ x ++ "\n"
  28.  
  29. limit :: (Eq a) => [a] -> a
  30. limit (x:y:ys) | x == y    = x
  31.                | otherwise = limit (y:ys)
  32. limit _                    = error "Miranda.limit: bad use"
  33.  
  34. ljustify :: Int -> String -> String
  35. ljustify n s = s ++ spaces (n - length s)
  36.  
  37. merge :: (Ord a) => [a] -> [a] -> [a]
  38. merge []         ys                     = ys
  39. merge xs         []                     = xs
  40. merge xxs@(x:xs) yys@(y:ys) | x <= y    = x : merge xs  yys
  41.                     | otherwise = y : merge xxs ys
  42.  
  43. rep :: Int -> b -> [b]
  44. rep n x = take n (repeat x)
  45.  
  46. rjustify :: Int -> String -> String
  47. rjustify n s = spaces (n - length s) ++ s
  48.  
  49. spaces :: Int -> String
  50. spaces 0 = ""
  51. spaces n = ' ' : spaces (n-1)
  52.  
  53. -------------
  54.  
  55. arctan x = atan x
  56. code c = ord c
  57. converse f a b = flip f a b
  58. decode n = chr n
  59. digit c = isDigit c
  60. e :: (Floating a) => a
  61. e = exp 1
  62. entier x = floor x
  63. filemode f = error "Miranda.filemode"
  64. --getenv
  65. hd xs = head xs
  66. hugenum :: (Floating a) => a
  67. hugenum = error "hugenum" --!!!
  68. integer x = x == truncate x
  69. letter c = isAlpha c
  70. map2 f xs ys = zipWith f xs ys
  71. --max
  72. max2 x y = max x y
  73. member xs x = x `elem` xs
  74. --min
  75. min2 x y = min x y
  76. mkset xs = nub xs
  77. neg x = negate x
  78. numval :: (Num a) => String -> a
  79. numval cs = read cs
  80. postfix xs x = xs ++ [x]
  81. --read
  82. scan f z l = scanl f z l
  83. --shownum !!!
  84. --showfloat !!!
  85. --showscaled !!!
  86. tinynum :: (Floating a) => a
  87. tinynum = error "tinynum"
  88. undef = error "undefined"
  89. zip2 xs ys = zip xs ys
  90. --zip
  91.